Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC: unused warnings #8359

Merged
merged 1 commit into from
Aug 23, 2022
Merged

Conversation

jeffro256
Copy link
Contributor

@jeffro256 jeffro256 commented May 28, 2022

This PR fixes 4 instances of -Wunused...

@@ -5127,7 +5124,6 @@ std::string wallet2::exchange_multisig_keys(const epee::wipeable_string &passwor
expanded_msgs.emplace_back(msg);

// reconstruct multisig account
crypto::public_key dummy;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is already fixed in one of the multisig PRs. Can you undo this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

@jeffro256 jeffro256 force-pushed the unused_warnings branch 2 times, most recently from b1710f6 to 50a9879 Compare May 29, 2022 21:57
@@ -3476,7 +3475,6 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
if (!first && blocks.empty())
{
m_node_rpc_proxy.set_height(m_blockchain.size());
refreshed = true;
Copy link
Contributor

@mj-xmr mj-xmr May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was set by the author to facilitate easier debugging, since with this variable in place, it appears in the locals debugging window.

I personally don't need it, but just saying that this is the reason why I haven't removed it myself.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my thought as well. I don't see any need to remove it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a leftover from this patch: #6097 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hyc pushed changes to keep the flag in and remove the warning

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffro256 "Easier debugging" was speculation. As it says in mooo's comment, he wanted to clean it up but probably forgot about it. We can ask him again to be sure but just silencing doesn't make much sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@selsta selsta Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12:34 <moneromooo> I had to reorder some code to fix... a timing info leak IIRC. In turn, this undid something I had fixed before, which I believe was a subtle race condition with the txpool.
12:35 <moneromooo> It was pretty subtle IIRC, and so I needed time to think about how to refix it after the move, and I never got to it. I do not remember the details of the race.
12:35 <moneromooo> I don't think I'm likely to ever get to it now.
12:43 <+selsta> ok ty, i guess i'll let the other decide if we keep the unused variable
12:45 <moneromooo> At this point, since it was to remind me, it could be replaced by a comment if people really hate it.

So either we remove the unused variable and add a comment or we keep it. Silencing doesn't make sense in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for commenting out rather than silencing.

There will surely be a lot of debugging to do there in future, but then it can be uncommented on demand, still not causing warnings to everybody else and not having to resort to compiler hacks, which might not be cross-platform.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should add some of mooo's commentary as a comment in the source too. Saves digging thru github issues to find out what it's all about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@mj-xmr mj-xmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, but please gather 2nd or even 3rd opinion about the wallet2 change.

@@ -38,5 +38,6 @@

void hash_extra_jh(const void *data, size_t length, char *hash) {
int r = jh_hash(HASH_SIZE * 8, data, 8 * length, (uint8_t*)hash);
(void) r; // silence -Wunused-variable
Copy link
Contributor

@mj-xmr mj-xmr May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before anybody mentions inconsistency of the casting style:

This is C, not C++, so static_cast<> can't be used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these are only unused because assert() is being no-op'd. These hash functions don't allocate memory so have no reason to fail. Maybe we can just get rid of r and the asserts too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah since hashbitlen is a compile-time constant, there should be no reason for jh_hash to not return SUCCESS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay changes are pushed for that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the wishy-washiness but I'm gonna take back what I said and go with your initial patch. Safer to leave the asserts in place so that they're present in Debug builds, and will catch any accidental misuses of the code in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make the assert statements conditional on whether NDEBUG is defined?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert() is already a #define that is empty when NDEBUG is defined. Do you mean conditionalizing the other statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if NDEBUG is defined, then don't check for error, otherwise do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, there's really no point checking for an non-success status since the only possible failure condition is if hashbitlen is wrong. Since it's a compile-time constant in our case the only way someone could use it wrong is if they modified the hash-extra function bodies. I put a comment above that line in this PR which explains why we are not checking for a failure result.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds good.

@jeffro256 jeffro256 force-pushed the unused_warnings branch 2 times, most recently from cc85eb4 to 82207fd Compare June 1, 2022 02:25
@jeffro256 jeffro256 changed the title GCC: general unused warnings GCC: unused warnings Jun 1, 2022
Comment on lines 3421 to 3423
// moneromooo-monero says this about the "refreshed" variable:
// "I had to reorder some code to fix... a timing info leak IIRC. In turn, this undid something I had fixed before, ... a subtle race condition with the txpool.
// It was pretty subtle IIRC, and so I needed time to think about how to refix it after the move, and I never got to it."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// moneromooo-monero says this about the "refreshed" variable:
// "I had to reorder some code to fix... a timing info leak IIRC. In turn, this undid something I had fixed before, ... a subtle race condition with the txpool.
// It was pretty subtle IIRC, and so I needed time to think about how to refix it after the move, and I never got to it."
// TODO: moneromooo-monero says this about the "refreshed" variable:
// "I had to reorder some code to fix... a timing info leak IIRC. In turn, this undid something I had fixed before, ... a subtle race condition with the txpool.
// It was pretty subtle IIRC, and so I needed time to think about how to refix it after the move, and I never got to it."
// https://github.com/monero-project/monero/pull/6097

TODO so that it can be quickly found via git grep. Also adding a URL for context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@moneromooo-monero
Copy link
Collaborator

At this point I'm unlikely to spend a lot of time thinking about it and fixing it well. So if people want to kill the warning, be my guest. I'd be better if people wanted to fix it properly instead of just killing the warning, but that's up to them.

@selsta
Copy link
Collaborator

selsta commented Jul 6, 2022

@jeffro256 Can you keep the refreshed variable untouched and only add the comment? We can keep the warning as a reminder for someone to look into, if it stays unfixed for another year then we can decide what to do next with it.

Sorry for this huge discussion :)

hash_extra: don't test for success in `jh_hash` and `skein_hash` since its guaranteed
device_ledger: move anonymous global variable apdu_verbose into .cpp file
Add comments to `refreshed` method variable in wallet2
@jeffro256
Copy link
Contributor Author

@selsta done!

@luigi1111 luigi1111 merged commit df02b56 into monero-project:master Aug 23, 2022
@jeffro256 jeffro256 deleted the unused_warnings branch October 31, 2023 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants